package 第一章基础算法.前缀和与差分.id798差分矩阵;

import java.util.Scanner;

/**
 *  用途：让原矩阵中的某一部分矩阵加上一个值
 *  关键：  dif[x1-1][y1-1] += c;
 *         dif[x2][y1-1] -= c;
 *         dif[x1-1][y2] -= c;
 *         dif[x2][y2] += c;
 */
public class Main {
    public static void main(String[] args) {
        //处理输入
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int q = scanner.nextInt();
        int[][] matrix = new int[n+1][m+1];
        for(int i = 1; i<=n;i++){
            for(int j = 1;j<=m;j++){
                matrix[i][j] = scanner.nextInt();
            }
        }
        //构建原矩阵的差分矩阵
        int[][] dif = new int[n+1][m+1];
        for(int i = 1;i<=n;i++){
            for(int j = 1;j<=m;j++){
                insert(dif,i,j,i,j,matrix[i][j]);
            }
        }
        while (q -- > 0){
            int x1 = scanner.nextInt();
            int y1 = scanner.nextInt();
            int x2 = scanner.nextInt();
            int y2 = scanner.nextInt();
            int c = scanner.nextInt();
            insert(dif,x1,y1,x2,y2,c);
        }
        //对操作后的差分矩阵求前缀矩阵
        int[][]res = new int[n+1][m+1];
        for(int i = 1;i<=n;i++){
            for(int j = 1;j<=m;j++){
                res[i][j] = res[i-1][j] + res[i][j-1] - res[i-1][j-1] + dif[i-1][j-1];
            }
        }
        //处理输出
        for(int i = 1;i<=n;i++){
            for(int j = 1;j<=m;j++){
                System.out.print(res[i][j]+ " ");
            }
            System.out.println();
        }
    }
    public static void insert(int[][]dif , int x1, int y1, int x2, int y2,int c){
        dif[x1-1][y1-1] += c;
        dif[x2][y1-1] -= c;
        dif[x1-1][y2] -= c;
        dif[x2][y2] += c;
    }
}

